package com.example.service.impl;

import com.example.dao.CommentDao;
import com.example.dao.ForumDao;
import com.example.entity.Comment;
import com.example.entity.Forum;
import com.example.service.ForumService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class ForumServiceImpl implements ForumService {
    @Autowired
    private ForumDao forumDao;
    @Autowired
    private CommentDao commentDao;
    @Override
    public int addForum(Integer userId,String content) {
        Date date =new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String createTime = format.format(date);

        return forumDao.addForum(userId,content,createTime);
    }

    @Override
    public List<Forum> listForum(Integer user_id) {
//       Forum forum= forumDao.listForum(user_id);
//        Date date =new Date();
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String createTime = format.format(date);
//        forum.setCreate_time(createTime);
        return forumDao.listForum(user_id);
    }

    @Override
    public List<Forum> listForumById(int user_id) {
        return forumDao.listForumById(user_id);
    }

    @Override
    public int deleteForum(@Param("share_id") int share_id, @Param("user_id") int user_id) {
        return forumDao.delete(share_id,user_id);
    }

}
